﻿using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using Safal.IncidentTracker.WebUI.HtmlHelpers;

namespace Safal.IncidentTracker.Tests
{
    [TestFixture]
    public class PagedList
    {
        [Test]
        public void CanCreate_PagedList_FromAGenericList()
        {
            // Arrange Act
            var strings = new List<string> { "one", "two", "three", "four", "five" };
            var list = new PagedList<string>(strings.AsQueryable(), 1, 2);

            // Assert
            Assert.That(list.TotalCount, Is.EqualTo(5));
            Assert.That(list.PageIndex, Is.EqualTo(1));
            Assert.That(list.PageSize, Is.EqualTo(2));
            Assert.That(list[0], Is.EqualTo("three"));
            Assert.That(list.HasPreviousPage, Is.True);
            Assert.That(list.HasNextPage, Is.True);

        }
        [Test]
        public void CanCreate_PagedList_FromIQueryable_UsingExtension()
        {
            // Arrange Act
            var strings = new List<string> { "one", "two", "three", "four", "five" };
            var list = strings.AsQueryable().ToPagedList(2, 2);
            
            // Assert
            Assert.That(list.TotalCount, Is.EqualTo(5));
            Assert.That(list.PageIndex, Is.EqualTo(2));
            Assert.That(list.PageSize, Is.EqualTo(2));
            Assert.That(list.TotalPages, Is.EqualTo(3));
            Assert.That(list.CurrentPage, Is.EqualTo(3));
            Assert.That(list[0], Is.EqualTo("five"));
            Assert.That(list.HasPreviousPage, Is.True);
            Assert.That(list.HasNextPage, Is.False);
        }
    }


}
